#ifdef WITH_CG

#pragma once
#include "shader.h"
#include <vector>
#include <map>
#include <Cg/cg.h>

namespace krryn{
namespace system_imp{
	class shader_catalog_cg;
	class shader_cg : public view::shader{
	public:
		shader_cg(shader_catalog_cg &a_Catalog, const std::string &a_Filename, CGcontext a_Context);
		virtual ~shader_cg();
		virtual void enable() = 0;
		virtual void disable() = 0;

		virtual std::string get_source(view::shader_type a_Type);
		virtual std::string get_compiled_source(view::shader_type a_Type);

		void check_error(CGcontext cgContext);
	protected:
		std::string m_Filename;

		bool m_CompileError;
		CGcontext m_Context;
		CGprogram m_VertexShader, m_PixelShader;
		CGprofile m_VertexProfile, m_PixelProfile;

		std::vector<std::map<std::string, CGparameter> > m_Params;

		// Must be called by the child's constructor!
		void init(std::string a_Filename);
		void load_params(view::shader_type a_Type, CGprogram a_Program);
		void throw_shader_param_error(view::shader_type a_Type, const std::string &a_Name);
	};
}
}

#endif